<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>异步编程</title>
</head>
<body>

    <button id="btn">click me</button>
    <p id="para">this is p element</p>
    
    <script>
        
        // 异步编程 小例子

        -function () {


            function fn (timeout,callback) {
                window.setTimeout(function () {
                    let data = '异步编程输出的结果';
                    callback(data);
                },timeout)
            }

            console.log(fn(2000,function (d) {
                console.log(d);
            }));

        } ();

        -function () {

            let btn = document.getElementById("btn");
            let para = document.getElementById("para");

            function fn (callback) {
                
                btn.onclick = function () {
                    let text = para.innerHTML;
                    callback(text);
                }

            }

            console.log(fn(function (d) {
                console.log(d); 
            }));


        } ();


    </script>
</body>
</html>